﻿goog.provide('ol.dmp.Point');
goog.provide('ol.dmp.algorithmsUtility');


ol.dmp.Point=function(options)
{

    this.x=(goog.isDef(options)&&goog.isDef(options.x))?options.x:0;
    this.y=(goog.isDef(options)&&goog.isDef(options.y))?options.y:0;

};

ol.dmp.Point.prototype.getCoordinates=function()
{
    return [this.x,this.y];
}


// 获取简单箭头的相关点
ol.dmp.algorithmsUtility.simplyArrow=function(options)
{
    var gridPoints = [new ol.dmp.Point({ x: options[0][0], y: options[0][1] }), new ol.dmp.Point({ x: options[1][0], y: options[1][1] })];

    var points = new Array();
    var controlPoints = new Array();
    var drawPoints = new Array();
    var points1 = new Array();
    var points2 = new Array();


    var isDraw = false;

    var curvePoint = new Array;
    curvePoint[0] = new ol.dmp.Point();
    curvePoint[0] = gridPoints[0];

    curvePoint[1] = new ol.dmp.Point();
    curvePoint[1].x = gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 0.001;
    curvePoint[1].y = gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 0.001;
    
    curvePoint[2] = new ol.dmp.Point();
    curvePoint[2] = gridPoints[1];

    //生成箭头控制点
    controlPoints[0] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.900000);
    controlPoints[1] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.900005);
    controlPoints[2] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.930000);
    controlPoints[3] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.930005);
    controlPoints[4] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.999995);
    controlPoints[5] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 1.000000);
    controlPoints[6] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.333333);
    controlPoints[7] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.333338);
    controlPoints[8] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.600000);
    controlPoints[9] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.600005);

    var k1 = (controlPoints[1].y - controlPoints[0].y) / (controlPoints[1].x - controlPoints[0].x);
    k1 = -(1 / k1);
    var b1 = controlPoints[0].y - k1 * controlPoints[0].x;
    var k2 = (controlPoints[3].y - controlPoints[2].y) / (controlPoints[3].x - controlPoints[2].x);
    k2 = -(1 / k2);
    var b2 = controlPoints[2].y - k2 * controlPoints[2].x;
    var k3 = (controlPoints[5].y - controlPoints[4].y) / (controlPoints[5].x - controlPoints[4].x);

    //-->add
    var k4 = (controlPoints[7].y - controlPoints[6].y) / (controlPoints[7].x - controlPoints[6].x);
    k4 = -(1 / k4);
    var b4 = controlPoints[6].y - k4 * controlPoints[6].x;

    var angle1 = 20;
    var radians1 = angle1 * (Math.PI / 180);
    var result1_d = Math.tan(radians1); 
    var result1 = result1_d;

    //斜率为15度的两条直线
    var k31 = (k3 + result1) / (1 - k3 * result1);
    var b31 = controlPoints[5].y - k31 * controlPoints[5].x;

    var k32 = (k3 - result1) / (1 + k3 * result1);
    var b32 = controlPoints[5].y - k32 * controlPoints[5].x;



    var angle2 = 10;
    var radians2 = angle2 * (Math.PI / 180);
    var result2_d = Math.tan(radians2);
    var result2 =result2_d;

    //斜率为5度的1两条直线
    var k33 = (k3 + result2) / (1 - k3 * result2);
    var b33 = controlPoints[5].y - k33 * controlPoints[5].x;

    var k34 = (k3 - result2) / (1 + k3 * result2);
    var b34 = controlPoints[5].y - k34 * controlPoints[5].x;

    drawPoints[0] = new ol.dmp.Point();
    drawPoints[0].x = controlPoints[5].x;
    drawPoints[0].y = controlPoints[5].y;



    //斜率为5度的2两条直线
    var angle4 = 5;
    var radians4 = angle4 * (Math.PI / 180);
    var result4_d = Math.tan(radians4);
    var result4 = result4_d;


    var k35 = (k3 + result4) / (1 - k3 * result4);
    var b35 = controlPoints[5].y - k35 * controlPoints[5].x;

    var k36 = (k3 - result4) / (1 + k3 * result4);
    var b36 = controlPoints[5].y - k36 * controlPoints[5].x;


    //15度夹角直线的交点
    drawPoints[1] = new ol.dmp.Point();
    drawPoints[1].x = (b31 - b1) / (k1 - k31);
    drawPoints[1].y = (b1 * k31 - b31 * k1) / (k31 - k1);

    drawPoints[2] = new ol.dmp.Point();
    drawPoints[2].x = (b32 - b1) / (k1 - k32);
    drawPoints[2].y = (b1 * k32 - b32 * k1) / (k32 - k1);

    //5度夹角1直线的交点
    drawPoints[3] = new ol.dmp.Point();
    drawPoints[3].x = (b33 - b2) / (k2 - k33);
    drawPoints[3].y = (b2 * k33 - b33 * k2) / (k33 - k2);

    drawPoints[4] = new ol.dmp.Point();
    drawPoints[4].x = (b34 - b2) / (k2 - k34);
    drawPoints[4].y = (b2 * k34 - b34 * k2) / (k34 - k2);


    //5度夹角2直线的交点
    drawPoints[5] = new ol.dmp.Point();
    drawPoints[5].x = (b35 - b4) / (k4 - k35);
    drawPoints[5].y = (b4 * k35 - b35 * k4) / (k35 - k4);

    drawPoints[6] = new ol.dmp.Point();
    drawPoints[6].x = (b36 - b4) / (k4 - k36);
    drawPoints[6].y = (b4 * k36 - b36 * k4) / (k36 - k4);

    var K35f = (drawPoints[5].y - drawPoints[3].y) / (drawPoints[5].x - drawPoints[3].x);
    var k46f = (drawPoints[6].y - drawPoints[4].y) / (drawPoints[6].x - drawPoints[4].x);
    drawPoints[5].x = (drawPoints[3].y - gridPoints[0].y + k1 * gridPoints[0].x - K35f * drawPoints[3].x) / (k1 - K35f);
    drawPoints[5].y = ((drawPoints[3].x - gridPoints[0].x) * k1 * K35f + K35f * gridPoints[0].y - k1 * drawPoints[3].y) / (K35f - k1);
    drawPoints[6].x = (drawPoints[4].y - gridPoints[0].y + k1 * gridPoints[0].x - k46f * drawPoints[4].x) / (k1 - k46f);
    drawPoints[6].y = ((drawPoints[4].x - gridPoints[0].x) * k1 * k46f + k46f * gridPoints[0].y - k1 * drawPoints[4].y) / (k46f - k1);   


    var linePoints = new Array();
    linePoints.push(drawPoints[5].getCoordinates());
    linePoints.push(drawPoints[3].getCoordinates());
    linePoints.push(drawPoints[1].getCoordinates());
    linePoints.push(drawPoints[0].getCoordinates());
    linePoints.push(drawPoints[2].getCoordinates());
    linePoints.push(drawPoints[4].getCoordinates());
    linePoints.push(drawPoints[6].getCoordinates());
    linePoints.push(drawPoints[5].getCoordinates());  //对首节点重复处理



    return linePoints;

};

/// 钳击箭头

ol.dmp.algorithmsUtility.diceArrow = function (options)
{
    var resultPoints = [];
    var gridPoints=[];
    for (var i = 0 ,length=options.length; i < length; i++) 
    {
        gridPoints.push(new ol.dmp.Point({ x: options[i][0], y: options[i][1] }));
    }

    /// 箭头控制点
    /// </summary>
    var controlPointsUp = new Array();
    var controlPointsLow = new Array();
    /// <summary>
    /// 上箭头
    /// </summary>
    var drawPointsUp = new Array();
    /// <summary>
    /// 下箭头
    /// </summary>
    var drawPointsLow = new Array();

    /// <summary>
    /// 上侧贝塞尔曲线
    /// </summary>
    var points1 = new Array();
    /// <summary>
    /// 中间的弧度贝塞尔曲线
    /// </summary>
    var points2 = new Array();
    /// <summary>
    /// 下侧贝塞尔曲线
    /// </summary>
    var points3 = new Array();
    //判断顺逆方向
    var isReasil = ol.dmp.algorithmsUtility.Bezier.ClockWise(gridPoints);
    if (isReasil != 1)
    {
        var temp = gridPoints[0];
        gridPoints[0] = gridPoints[1];
        gridPoints[1] = temp;
        isReasil = 1;
    }
    var curvePointLow=new Array();
    var curvePointUp=new Array();
    var MidPoint, UpPoint, EndPoint, MidControlPoint, MidBackPoint, UpControlPoint, LowControlPoint;
    var k_input, k_inputchuixian, L, k1Up, k2Up, b1Up, b2Up, k3Up, angle1Up, radians1Up, result1_dUp, result1Up;
    var angle2Up, k31Up, k32Up, b31Up, b32Up, radians2Up, k33Up, result2_dUp, result2Up, b33Up, b34Up, k34Up;
    var k1Low, b1Low, k2Low, b2Low, k3Low, angle1Low, radians1Low, result1_dLow, result1Low, k31Low, b31Low, k32Low, b32Low;
    var angle2Low, radians2Low, result2_dLow, result2Low, k33Low, b33Low, k34Low, b34Low;
    //起始两点的中间点
    MidPoint = new ol.dmp.Point({x:(gridPoints[0].x + gridPoints[1].x) / 2,y:(gridPoints[0].y + gridPoints[1].y) / 2});

    //起始输入两点的直线斜率
    k_input = (gridPoints[1].y - gridPoints[0].y) / (gridPoints[1].x - gridPoints[0].x);
    if (k_input == 0)
    {
        return resultPoints;
    }
    //中轴线斜率
    k_inputchuixian = -(1 / k_input);

    //得到箭头端点的对称点
    UpPoint = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(k_inputchuixian, MidPoint, gridPoints[2]);

    //保存第四点信息 供只画三点时构建第四点
    m_ForthPoint = UpPoint;

    //中轴线终点
    EndPoint = new ol.dmp.Point({x:(UpPoint.x + gridPoints[2].x) / 2,y:(UpPoint.y + gridPoints[2].y) / 2});

    //中间控制点
    MidControlPoint = new ol.dmp.Point({x:MidPoint.x + (EndPoint.x - MidPoint.x) * 1 / 16,y:MidPoint.y + (EndPoint.y - MidPoint.y) * 1 / 16});


    //中间后部控制点
    MidBackPoint = new ol.dmp.Point({x:MidPoint.x - (EndPoint.x - MidPoint.x) * 1 / 4,y:MidPoint.y - (EndPoint.y - MidPoint.y) * 1 / 4});



    //上控制点  与输入两点的直线平行，距离MidControlPoint为3/4的输入两点线段长
    L = Math.sqrt((gridPoints[1].x - gridPoints[0].x) * (gridPoints[1].x - gridPoints[0].x) +
        (gridPoints[1].y - gridPoints[0].y) * (gridPoints[1].y - gridPoints[0].y));

    var upptx = MidControlPoint.x - 4 * L / (4 * Math.sqrt(k_input * k_input + 1));
    UpControlPoint = new ol.dmp.Point({
        x: upptx,
        y: MidControlPoint.y + k_input * (upptx - MidControlPoint.x)
        });


    //下控制点
    var lowptx = MidControlPoint.x + 3 * L / (4 * Math.sqrt(k_input * k_input + 1));
    LowControlPoint = new ol.dmp.Point({
        x: lowptx,
        y: MidControlPoint.y + k_input * (lowptx - MidControlPoint.x)
        });

    var updis = Math.sqrt((UpControlPoint.x - gridPoints[0].x) * (UpControlPoint.x - gridPoints[0].x) +
        (UpControlPoint.y - gridPoints[0].y) * (UpControlPoint.y - gridPoints[0].y));
    var lowdis = Math.sqrt((LowControlPoint.x - gridPoints[0].x) * (LowControlPoint.x - gridPoints[0].x) +
        (LowControlPoint.y - gridPoints[0].y) * (LowControlPoint.y - gridPoints[0].y));
    if (updis > lowdis && isReasil == 1)
    {
        var temp = UpControlPoint;
        UpControlPoint = LowControlPoint;
        LowControlPoint = temp;
    }
            //上箭头的中轴线
    curvePointUp = new Array();
    curvePointUp[0] = new ol.dmp.Point({x:(gridPoints[0].x + MidControlPoint.x) / 2,y:(gridPoints[0].y + MidControlPoint.y) / 2});
    

    
    var upX=0,upY=0;
    if (gridPoints.length == 4 && gridPoints[3] != null)
    {
        upX = 2 * UpControlPoint.x - 0.5 * (curvePointUp[0].x + gridPoints[3].x);
        upY = 2 * UpControlPoint.y - 0.5 * (curvePointUp[0].y + gridPoints[3].y);
        curvePointUp[2] = gridPoints[3];
    }
    else
    {
        upX = 2 * UpControlPoint.x - 0.5 * (curvePointUp[0].x + UpPoint.x);
        upY = 2 * UpControlPoint.y - 0.5 * (curvePointUp[0].y + UpPoint.y);
        curvePointUp[2] = UpPoint;
    }
    curvePointUp[1] = new ol.dmp.Point({x:upX,y:upY});


    //生成上箭头控制点
    controlPointsUp[0] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.900000);
    controlPointsUp[1] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.900005);
    controlPointsUp[2] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.930000);
    controlPointsUp[3] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.930005);
    controlPointsUp[4] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.999995);
    controlPointsUp[5] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 1.000000);
    controlPointsUp[6] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.333333);
    controlPointsUp[7] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.333338);
    controlPointsUp[8] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.600000);
    controlPointsUp[9] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointUp, 0.600005);


    //上箭头的箭标处理
    k1Up = (controlPointsUp[1].y - controlPointsUp[0].y) / (controlPointsUp[1].x - controlPointsUp[0].x);
    k1Up = -(1 / k1Up);
    b1Up = controlPointsUp[0].y - k1Up * controlPointsUp[0].x;
    k2Up = (controlPointsUp[3].y - controlPointsUp[2].y) / (controlPointsUp[3].x - controlPointsUp[2].x);
    k2Up = -(1 / k2Up);
    b2Up = controlPointsUp[2].y - k2Up * controlPointsUp[2].x;
    k3Up = (controlPointsUp[5].y - controlPointsUp[4].y) / (controlPointsUp[5].x - controlPointsUp[4].x);


    angle1Up = 20;
    radians1Up = angle1Up * (Math.PI / 180);
    result1_dUp = Math.tan(radians1Up);
    result1Up = result1_dUp;

    //斜率为30度的两条直线
    k31Up = (k3Up + result1Up) / (1 - k3Up * result1Up);
    b31Up = controlPointsUp[5].y - k31Up * controlPointsUp[5].x;

    k32Up = (k3Up - result1Up) / (1 + k3Up * result1Up);
    b32Up = controlPointsUp[5].y - k32Up * controlPointsUp[5].x;


    angle2Up = 10;
    radians2Up = angle2Up * (Math.PI / 180);
    result2_dUp = Math.tan(radians2Up);
    result2Up = result2_dUp;

    //斜率为15度的两条直线
    k33Up = (k3Up + result2Up) / (1 - k3Up * result2Up);
    b33Up = controlPointsUp[5].y - k33Up * controlPointsUp[5].x;

    k34Up = (k3Up - result2Up) / (1 + k3Up * result2Up);
    b34Up = controlPointsUp[5].y - k34Up * controlPointsUp[5].x;

    drawPointsUp[0] = new ol.dmp.Point({x:controlPointsUp[5].x,y:controlPointsUp[5].y});


    //30度夹角直线的交点
    drawPointsUp[1] = new ol.dmp.Point({x:(b31Up - b1Up) / (k1Up - k31Up),y:(b1Up * k31Up - b31Up * k1Up) / (k31Up - k1Up)});


    drawPointsUp[2] = new ol.dmp.Point({x:(b32Up - b1Up) / (k1Up - k32Up),y:(b1Up * k32Up - b32Up * k1Up) / (k32Up - k1Up)});


    //15度夹角直线的交点
    drawPointsUp[3] = new ol.dmp.Point({x:(b33Up - b2Up) / (k2Up - k33Up),y:(b2Up * k33Up - b33Up * k2Up) / (k33Up - k2Up)});


    drawPointsUp[4] = new ol.dmp.Point({x:(b34Up - b2Up) / (k2Up - k34Up),y:(b2Up * k34Up - b34Up * k2Up) / (k34Up - k2Up)});

            //下箭头的中轴线
    curvePointLow = new Array();
    curvePointLow[0] = new ol.dmp.Point({x:(gridPoints[1].x + MidControlPoint.x) / 2,y:(gridPoints[1].y + MidControlPoint.y) / 2});


    curvePointLow[1] = new ol.dmp.Point({
        x:2 * LowControlPoint.x - 0.5 * (curvePointLow[0].x + gridPoints[2].x),
        y:2 * LowControlPoint.y - 0.5 * (curvePointLow[0].y + gridPoints[2].y)
        });
    curvePointLow[2] = gridPoints[2];

    //生成下箭头控制点
    controlPointsLow[0] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.900000);
    controlPointsLow[1] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.900005);
    controlPointsLow[2] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.930000);
    controlPointsLow[3] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.930005);
    controlPointsLow[4] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.999995);
    controlPointsLow[5] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 1.000000);
    controlPointsLow[6] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.333333);
    controlPointsLow[7] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.333338);
    controlPointsLow[8] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.600000);
    controlPointsLow[9] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePointLow, 0.600005);

    //下箭头的箭标处理         
    k1Low = (controlPointsLow[1].y - controlPointsLow[0].y) / (controlPointsLow[1].x - controlPointsLow[0].x);
    k1Low = -(1 / k1Low);
    b1Low = controlPointsLow[0].y - k1Low * controlPointsLow[0].x;
    k2Low = (controlPointsLow[3].y - controlPointsLow[2].y) / (controlPointsLow[3].x - controlPointsLow[2].x);
    k2Low = -(1 / k2Low);
    b2Low = controlPointsLow[2].y - k2Low * controlPointsLow[2].x;
    k3Low = (controlPointsLow[5].y - controlPointsLow[4].y) / (controlPointsLow[5].x - controlPointsLow[4].x);


    angle1Low = 20;
    radians1Low = angle1Low * (Math.PI / 180);
    result1_dLow = Math.tan(radians1Low);
    result1Low = result1_dLow;

    //斜率为30度的两条直线
    k31Low = (k3Low + result1Low) / (1 - k3Low * result1Low);
    b31Low = controlPointsLow[5].y - k31Low * controlPointsLow[5].x;

    k32Low = (k3Low - result1Low) / (1 + k3Low * result1Low);
    b32Low = controlPointsLow[5].y - k32Low * controlPointsLow[5].x;


    angle2Low = 10;
    radians2Low = angle2Low * (Math.PI / 180);
    result2_dLow = Math.tan(radians2Low);
    result2Low = result2_dLow;

    //斜率为15度的两条直线
    k33Low = (k3Low + result2Low) / (1 - k3Low * result2Low);
    b33Low = controlPointsLow[5].y - k33Low * controlPointsLow[5].x;

    k34Low = (k3Low - result2Low) / (1 + k3Low * result2Low);
    b34Low = controlPointsLow[5].y - k34Low * controlPointsLow[5].x;

    drawPointsLow[0] =new ol.dmp.Point({x:controlPointsLow[5].x,y:controlPointsLow[5].y});


    //30度夹角直线的交点
    drawPointsLow[1] = new ol.dmp.Point({x:(b31Low - b1Low) / (k1Low - k31Low),y:(b1Low * k31Low - b31Low * k1Low) / (k31Low - k1Low)});


    drawPointsLow[2] = new ol.dmp.Point({
        x:(b32Low - b1Low) / (k1Low - k32Low),
        y:(b1Low * k32Low - b32Low * k1Low) / (k32Low - k1Low)});

    //15度夹角直线的交点
    drawPointsLow[3] = new ol.dmp.Point({
        x:(b33Low - b2Low) / (k2Low - k33Low),
        y:(b2Low * k33Low - b33Low * k2Low) / (k33Low - k2Low)});

    drawPointsLow[4] = new ol.dmp.Point({
        x:(b34Low - b2Low) / (k2Low - k34Low),
        y:(b2Low * k34Low - b34Low * k2Low) / (k34Low - k2Low)});
    
    var linePoints=[];

    if (isReasil == 1)
    {
        //添加贝塞尔曲线所需的点
        points1[0] = gridPoints[0];
        points1[1] = UpControlPoint;
        points1[2] = drawPointsUp[4];
        points1[3] = drawPointsUp[4];
        points2[0] = drawPointsUp[3];
        var pt1x= ((MidControlPoint.x + UpControlPoint.x) / 2 + UpControlPoint.x) / 2;
        var pt1y= ((MidControlPoint.y + UpControlPoint.y) / 2 + UpControlPoint.y) / 2;
        var pt2x=((MidControlPoint.x + LowControlPoint.x) / 2 + LowControlPoint.x) / 2;
        var pt2y=((MidControlPoint.y + LowControlPoint.y) / 2 + LowControlPoint.y) / 2;
        points2[1] = new ol.dmp.Point({x:pt1x,y:pt1y});
        points2[2] = new ol.dmp.Point({x:pt2x,y:pt2y});
        points2[3] = drawPointsLow[4];
        points3[0] = gridPoints[1];
        points3[1] = LowControlPoint;
        points3[2] = drawPointsLow[3];
        points3[3] = drawPointsLow[3];
        
        linePoints= linePoints.concat( ol.dmp.algorithmsUtility.Bezier.GetBezier3(points1));
        linePoints.push(drawPointsUp[2]);
        linePoints.push(drawPointsUp[0]);
        linePoints.push(drawPointsUp[1]);
        linePoints.push(drawPointsUp[3]);
        linePoints = linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points2));
        linePoints.push(drawPointsLow[4]);
        linePoints.push(drawPointsLow[2]);
        linePoints.push(drawPointsLow[0]);
        linePoints.push(drawPointsLow[1]);
        linePoints = linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier31(points3));


    }

    for (var i = 0,length=linePoints.length; i < length; i++)
    {
        resultPoints.push(linePoints[i].getCoordinates());
    }

    if (linePoints.length > 0)  // 形成闭环，主要是为了在绘制过程中外包围线好看
    {
        resultPoints.push(linePoints[0].getCoordinates());
    }

    return resultPoints;
};


/// 攻击箭头 (3或者4个顶点)
ol.dmp.algorithmsUtility.attackArrow = function (options)
{
    var resultPoints = [];
    var gridPoints=[];
    for (var i = 0 ,length=options.length; i < length; i++) 
    {
        gridPoints.push(new ol.dmp.Point({ x: options[i][0], y: options[i][1] }));
    }

    if (gridPoints.length == 3)  // 如果只有三个顶点，则人工添加一个
    {
        var middlex = (gridPoints[0].x + gridPoints[1].x + gridPoints[2].x) / 3;
        var middley = (gridPoints[0].y + gridPoints[1].y + gridPoints[2].y) / 3;
        gridPoints[2] = new ol.dmp.Point({ x: middlex, y: middley });
        gridPoints.push(new ol.dmp.Point({ x: options[2][0], y: options[2][1] }));
    }

    //判断顺逆方向
    var isReasil = ol.dmp.algorithmsUtility.Bezier.ClockWise(gridPoints);
    if (isReasil != 1)
    {
        var temp = gridPoints[0];
        gridPoints[0] = gridPoints[1];
        gridPoints[1] = temp;
        isReasil = 1;
    }

    var controlPoints = new Array();
    var drawPoints =  new Array();
    // 左曲线控制点      
    var points1 = new Array();
    // 右曲线控制点（逆序）
    var points2 = new Array();
    var curvePoint = new Array();
    curvePoint[0] = new ol.dmp.Point({x:(gridPoints[0].x + gridPoints[1].x) / 2,y:(gridPoints[0].y + gridPoints[1].y) / 2});

    //左侧贝塞尔曲线起点
    points1[0] = gridPoints[0];

    curvePoint[1] = new ol.dmp.Point({
        x:2 * gridPoints[2].x - 0.5 * (curvePoint[0].x + gridPoints[3].x),
        y:2 * gridPoints[2].y - 0.5 * (curvePoint[0].y + gridPoints[3].y)
    });
    curvePoint[2] = gridPoints[3];

    //生成箭头控制点
    controlPoints[0] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.900000);
    controlPoints[1] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.900005);
    controlPoints[2] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.930000);
    controlPoints[3] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.930005);
    controlPoints[4] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.999995);
    controlPoints[5] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 1.000000);
    controlPoints[6] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.333333);
    controlPoints[7] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.333338);
    controlPoints[8] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.600000);
    controlPoints[9] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoint, 0.600005);

    var k1 = (controlPoints[1].y - controlPoints[0].y) / (controlPoints[1].x - controlPoints[0].x);
    k1 = -(1 / k1);
    var b1 = controlPoints[0].y - k1 * controlPoints[0].x;
    var k2 = (controlPoints[3].y - controlPoints[2].y) / (controlPoints[3].x - controlPoints[2].x);
    k2 = -(1 / k2);
    var b2 = controlPoints[2].y - k2 * controlPoints[2].x;
    var k3 = (controlPoints[5].y - controlPoints[4].y) / (controlPoints[5].x - controlPoints[4].x);

    var angle1 = 20;
    var radians1 = angle1 * (Math.PI / 180);
    var result1_d = Math.tan(radians1);
    var result1 = result1_d;

    //斜率为15度的两条直线
    var k31 = (k3 + result1) / (1 - k3 * result1);
    var b31 = controlPoints[5].y - k31 * controlPoints[5].x;

    var k32 = (k3 - result1) / (1 + k3 * result1);
    var b32 = controlPoints[5].y - k32 * controlPoints[5].x;


    var angle2 = 10;
    var radians2 = angle2 * (Math.PI / 180);
    var result2_d = Math.tan(radians2);
    var result2 =result2_d;

    //斜率为5度的两条直线
    var k33 = (k3 + result2) / (1 - k3 * result2);
    var b33 = controlPoints[5].y - k33 * controlPoints[5].x;

    var k34 = (k3 - result2) / (1 + k3 * result2);
    var b34 = controlPoints[5].y - k34 * controlPoints[5].x;

    drawPoints[0] = new ol.dmp.Point({x:controlPoints[5].x,y:controlPoints[5].y});

    //15度夹角直线的交点
    drawPoints[1] = new ol.dmp.Point({x:(b31 - b1) / (k1 - k31),y:(b1 * k31 - b31 * k1) / (k31 - k1)});


    drawPoints[2] = new ol.dmp.Point({x:(b32 - b1) / (k1 - k32),y:(b1 * k32 - b32 * k1) / (k32 - k1)});

    //5度夹角直线的交点
    drawPoints[3] = new ol.dmp.Point({x:(b33 - b2) / (k2 - k33),y:(b2 * k33 - b33 * k2) / (k33 - k2)});

    drawPoints[4] = new ol.dmp.Point({x:(b34 - b2) / (k2 - k34),y:(b2 * k34 - b34 * k2) / (k34 - k2)});


    //添加贝塞尔曲线所需的点 左侧

    points1[1] = curvePoint[1];
    points1[3] = drawPoints[4];
    points1[2] = points1[3];
    //右侧
    points2[3] = gridPoints[1];
    points2[1] = drawPoints[3]; 
    points2[0] = drawPoints[3];
    points2[2] = curvePoint[1];

    var linePoints=[];

    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points1))

    linePoints.push(drawPoints[2]);
    linePoints.push(drawPoints[0]);
    linePoints.push(drawPoints[1]);

    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points2))


    for (var i = 0, length = linePoints.length; i < length; i++)
    {
        resultPoints.push(linePoints[i].getCoordinates());
    }

    if (linePoints.length > 0)  // 形成闭环，主要是为了在绘制过程中外包围线好看
    {
        resultPoints.push(linePoints[0].getCoordinates());
    }

    return resultPoints;

};


/// 生成集结域(2点)
ol.dmp.algorithmsUtility.rallyRegion = function (options)
{
    var resultPoints = [];
    var gridPoints=[];
    for (var i = 0 ,length=options.length; i < length; i++) 
    {
        gridPoints.push(new ol.dmp.Point({ x: options[i][0], y: options[i][1] }));
    }

    var points1 = new Array();      
    var points2 = new Array();
    var points3 = new Array();
    var points4 = new Array();
    var points5 = new Array();
    var points6 = new Array();
    var points7 = new Array();
    var points8 = new Array();
    var points9 = new Array();

    //中间点
    var needchange = false;
    var uporlow = 0;
    var MidPoint = new ol.dmp.Point({x:(gridPoints[0].x + gridPoints[1].x) / 2,y:(gridPoints[0].y + gridPoints[1].y) / 2});

    //1/8点
    var Point81 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) / 8,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) / 8
        });


    //7/8点
    var Point87 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 7 / 8,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 7 / 8
        });

    //1/4点
    var Point41 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) / 4,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) / 4
        });


    //3/4点
    var Point43 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 3 / 4,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 3 / 4
        });


    //3/8点
    var Point83 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 3 / 8,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 3 / 8
        });


    //5/8点
    var Point85 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 5 / 8,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 5 / 8
        });


    //1/16点
    var Point161 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) / 16,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) / 16
        });

    //15/16点
    var Point1615 = new ol.dmp.Point({
        x:gridPoints[0].x + (gridPoints[1].x - gridPoints[0].x) * 15 / 16,
        y:gridPoints[0].y + (gridPoints[1].y - gridPoints[0].y) * 15 / 16
        });


    //两点 斜率
    var xl = (gridPoints[1].y - gridPoints[0].y) / (gridPoints[1].x - gridPoints[0].x);

    if (xl == 0)
    {
        return resultPoints;
    }

    //垂线的斜率
    var xlt = -(1 / xl);

    //上部垂直的点
    
    var L = Math.sqrt((gridPoints[1].y - gridPoints[0].y) * (gridPoints[1].y - gridPoints[0].y) + (gridPoints[1].x - gridPoints[0].x) * (gridPoints[1].x - gridPoints[0].x));
    var upx = Math.sqrt((L / 4) * (L / 4) / (xlt * xlt + 1)
        ) + MidPoint.x;
    var upy = MidPoint.y + xlt * (upx - MidPoint.x);
    var UperPoint = new ol.dmp.Point({x:upx,y:upy});


    //上部1/8的点
    var Uper81Point = new ol.dmp.Point();
    Uper81Point.x = Math.sqrt((L / 5) * (L / 5) / (xlt * xlt + 1)
        ) + Point81.x;
    Uper81Point.y = Point81.y + xlt * (Uper81Point.x - Point81.x);

    //上部7/8的点
    var Uper87Point = new ol.dmp.Point();
    Uper87Point.x = Math.sqrt((L / 5) * (L / 5) / (xlt * xlt + 1)
        ) + Point87.x;
    Uper87Point.y = Point87.y + xlt * (Uper87Point.x - Point87.x);


    //上部1/4的点
    var Uper41Point = new ol.dmp.Point();
    Uper41Point.x = Math.sqrt((L / 4) * (L / 4) / (xlt * xlt + 1)
        ) + Point41.x;
    Uper41Point.y = Point41.y + xlt * (Uper41Point.x - Point41.x);

    //上部3/4的点
    var Uper43Point = new ol.dmp.Point();
    Uper43Point.x = Math.sqrt((L / 4) * (L / 4) / (xlt * xlt + 1)
        ) + Point43.x;
    Uper43Point.y = Point43.y + xlt * (Uper43Point.x - Point43.x);
    //上部1/16的点
    var Uper161Point = new ol.dmp.Point();
    Uper161Point.x = Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
        ) + gridPoints[0].x;
    Uper161Point.y = gridPoints[0].y + xlt * (Uper161Point.x - gridPoints[0].x);

    //上部15/16的点
    var Uper1615Point = new ol.dmp.Point();
    Uper1615Point.x = Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
        ) + gridPoints[1].x;
    Uper1615Point.y = gridPoints[1].y + xlt * (Uper1615Point.x - gridPoints[1].x);



    //下部垂直的点
    var LowerPoint = new ol.dmp.Point();
    LowerPoint.x = MidPoint.x - Math.sqrt((L / 10) * (L / 10) / (xlt * xlt + 1)
        );
    LowerPoint.y = MidPoint.y + xlt * (LowerPoint.x - MidPoint.x);


    //下部1/8的点
    var Lower81Point = new ol.dmp.Point();
    Lower81Point.x = Point81.x - Math.sqrt((L / 5) * (L / 5) / (xlt * xlt + 1)
       );
    Lower81Point.y = Point81.y + xlt * (Lower81Point.x - Point81.x);

    //下部7/8的点
    var Lower87Point = new ol.dmp.Point();
    Lower87Point.x = Point87.x - Math.sqrt((L / 5) * (L / 5) / (xlt * xlt + 1)
       );
    Lower87Point.y = Point87.y + xlt * (Lower87Point.x - Point87.x);


    //下部3/8的点
    var Lower83Point = new ol.dmp.Point();
    Lower83Point.x = Point83.x - Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
       );
    Lower83Point.y = Point83.y + xlt * (Lower83Point.x - Point83.x);

    //下部1/4的点
    var Lower41Point = new ol.dmp.Point();
    Lower41Point.x = Point41.x - Math.sqrt((L / 4) * (L / 4) / (xlt * xlt + 1)
       );
    Lower41Point.y = Point41.y + xlt * (Lower41Point.x - Point41.x);


    //下部3/4的点
    var Lower43Point = new ol.dmp.Point();
    Lower43Point.x = Point43.x - Math.sqrt((L / 4) * (L / 4) / (xlt * xlt + 1)
       );
    Lower43Point.y = Point43.y + xlt * (Lower43Point.x - Point43.x);

    //下部5/8的点
    var Lower85Point = new ol.dmp.Point();
    Lower85Point.x = Point85.x - Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
       );
    Lower85Point.y = Point85.y + xlt * (Lower85Point.x - Point85.x);
    //下部1/16点
    var Lower161Point = new ol.dmp.Point();
    Lower161Point.x = -Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
        ) + gridPoints[0].x;
    Lower161Point.y = gridPoints[0].y + xlt * (Lower161Point.x - gridPoints[0].x);

    //下部15/16点
    var Lower1615Point = new ol.dmp.Point();
    Lower1615Point.x = -Math.sqrt((L / 6) * (L / 6) / (xlt * xlt + 1)
        ) + gridPoints[1].x;
    Lower1615Point.y = gridPoints[1].y + xlt * (Lower1615Point.x - gridPoints[1].x);


    var linePoints=new Array();

    if (gridPoints[1].y > gridPoints[0].y)         // 此处是自己瞎写的，没有根据，源代码因为需要用到高程做判断，所以删掉了。
    {
        needchange = true;
    }

    if (needchange)
    {
        Uper161Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper161Point);
        Uper81Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper81Point);
        Uper41Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper41Point);
        UperPoint = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], UperPoint);
        Uper43Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper43Point);
        Uper87Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper87Point);
        Uper1615Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Uper1615Point);

        Lower1615Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower1615Point);
        Lower87Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower87Point);
        Lower43Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower43Point);
        Lower85Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower85Point);
        LowerPoint = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], LowerPoint);
        Lower83Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower83Point);
        Lower41Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower41Point);
        Lower81Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower81Point);
        Lower161Point = ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint(gridPoints[0], gridPoints[1], Lower161Point);
    }
    points1[0] = gridPoints[0];
    points1[1] = Uper161Point;
    points1[2] = Uper81Point;
    points1[3] = Uper81Point;

    //
    points2[0] = Uper81Point;
    points2[1] = Uper41Point;
    points2[2] = UperPoint;
    points2[3] = UperPoint;

    //
    points3[0] = UperPoint;
    points3[1] = Uper43Point;
    points3[2] = Uper87Point;
    points3[3] = Uper87Point;

    //////
    points4[0] = Uper87Point;
    points4[1] = Uper1615Point;
    points4[2] = gridPoints[1];
    points4[3] = gridPoints[1];


    //////
    points5[0] = gridPoints[1];
    points5[1] = Lower1615Point;
    points5[2] = Lower87Point;
    points5[3] = Lower87Point;


    //////
    points6[0] = Lower87Point;
    points6[1] = Lower43Point;
    points6[2] = Lower85Point;
    points6[3] = Lower85Point;

    points7[0] = Lower85Point;
    points7[1] = LowerPoint;
    points7[2] = Lower83Point;
    points7[3] = Lower83Point;

    points8[0] = Lower83Point;
    points8[1] = Lower41Point;
    points8[2] = Lower81Point;
    points8[3] = Lower81Point;

    points9[0] = Lower81Point;
    points9[1] = Lower161Point;
    points9[2] = gridPoints[0];
    points9[3] = gridPoints[0];

    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points1));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points2));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points3));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points4));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points5));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points6));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points7));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points8));
    linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(points9));


    for (var i = 0, length = linePoints.length; i < length; i++)
    {
        resultPoints.push(linePoints[i].getCoordinates());
    }

    if (linePoints.length > 0)  // 形成闭环，主要是为了在绘制过程中外包围线好看
    {
        resultPoints.push(linePoints[0].getCoordinates());
    }

    return resultPoints;

}


/// 多箭头点的生成， 支持两个以上的点，//长的非常丑
/// 实际上只不过是把生成的单箭头的最后一个顶点连接起来而已，意义不大。
ol.dmp.algorithmsUtility.multiArrow = function (options)
{
    var arrowPoints = new Array();
    var resultArrowPoints = new Array();
    var resultPoints = [];
    var length = options.length;
    var lengthflag = length % 4;
    var arrowCount =Math.floor( length / 4);
    for (var i = 0, length = options.length; i < length; i++)
    {
        arrowPoints.push(new ol.dmp.Point({ x: options[i][0], y: options[i][1] }));
    }
    for (var i = 0; i < arrowCount; i++)
    {
        var end = (i + 1) * 4 ;

        var singleArrowPoints = arrowPoints.slice(i * 4, (i + 1) * 4 );
        resultArrowPoints = resultArrowPoints.concat(getSingleArrow(singleArrowPoints))
    }


    if (lengthflag == 2)
    {
        resultArrowPoints.push(arrowPoints[arrowPoints.length - 2]);
        resultArrowPoints.push(arrowPoints[arrowPoints.length - 1]);
    }
    else if (lengthflag == 3)
    {
        var middlex = (arrowPoints[arrowPoints.length - 3].x + arrowPoints[arrowPoints.length - 2].x + arrowPoints[arrowPoints.length - 1].x) / 3;
        var middley = (arrowPoints[arrowPoints.length - 3].y + arrowPoints[arrowPoints.length - 2].y + arrowPoints[arrowPoints.length - 1].y) / 3;
        var center = new ol.dmp.Point({ x: middlex, y: middley });
       
        var latsArrowPoints = new Array();
        latsArrowPoints.push(arrowPoints[arrowPoints.length - 3]);
        latsArrowPoints.push(arrowPoints[arrowPoints.length - 2]);
        latsArrowPoints.push(center);
        latsArrowPoints.push(arrowPoints[arrowPoints.length - 1]);

        resultArrowPoints = resultArrowPoints.concat(getSingleArrow(latsArrowPoints))
    }

    for (var i = arrowCount-1; i >=0; i--)   // 形成最后的闭环
    {
        resultArrowPoints.push(arrowPoints[(i * 4)+1]);
    }
    resultArrowPoints.push(arrowPoints[0]);

    for (var i = 0, length = resultArrowPoints.length; i < length; i++)
    {
        resultPoints.push(resultArrowPoints[i].getCoordinates());
    }

    return resultPoints;


    /// 获取一个箭头上的点(参数需要四个点)  // 
    function getSingleArrow(spoints)
    {
        var points = spoints.slice();
        var curvePoints = new Array();
        var leftPoints = new Array();
        var rightPoints = new Array();
        var controlPoints = new Array();
        var drawPoints = new Array();


        var isReasil = ol.dmp.algorithmsUtility.Bezier.ClockWise(points);
        if (isReasil != 1)
        {
            var temp = points[0];
            points[0] = points[1];
            points[1] = temp;
            //isReasil = 1;
        }


        curvePoints[0] = new ol.dmp.Point({x:(points[0].x + points[1].x) / 2,y:(points[0].y + points[1].y) / 2});

        //左侧贝塞尔曲线起点
        leftPoints[0] = points[0];
        //右侧贝塞尔曲线起点
        rightPoints[0] = points[1];

        curvePoints[1] = new ol.dmp.Point({
            x:(2 * points[2].x - 0.5 * (curvePoints[0].x + points[3].x)),
            y:(2 * points[2].y - 0.5 * (curvePoints[0].y + points[3].y))
        });

        curvePoints[2] = points[3];

        //生成箭头控制点
        controlPoints[0] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.90000);
        controlPoints[1] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.90005);
        controlPoints[2] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.93000);
        controlPoints[3] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.93005);
        controlPoints[4] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.999995);
        controlPoints[5] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 1.000000);
        controlPoints[6] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.333333);
        controlPoints[7] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.333338);
        controlPoints[8] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.600000);
        controlPoints[9] = ol.dmp.algorithmsUtility.Bezier.BezierPoint2(curvePoints, 0.600005);


        var k1 = (controlPoints[1].y - controlPoints[0].y) / (controlPoints[1].x - controlPoints[0].x);
        k1 = -(1 / k1);
        var b1 = controlPoints[0].y - k1 * controlPoints[0].x;
        var k2 = (controlPoints[3].y - controlPoints[2].y) / (controlPoints[3].x - controlPoints[2].x);
        k2 = -(1 / k2);
        var b2 = controlPoints[2].y - k2 * controlPoints[2].x;
        var k3 = (controlPoints[5].y - controlPoints[4].y) / (controlPoints[5].x - controlPoints[4].x);

        var angle1 = 20;
        var radians1 = angle1 * (Math.PI / 180);
        var result1_d = Math.tan(radians1);
        var result1 = result1_d;

        //斜率为30度的两条直线
        var k31 = (k3 + result1) / (1 - k3 * result1);
        var b31 = controlPoints[5].y - k31 * controlPoints[5].x;

        var k32 = (k3 - result1) / (1 + k3 * result1);
        var b32 = controlPoints[5].y - k32 * controlPoints[5].x;


        var angle2 = 10;
        var radians2 = angle2 * (Math.PI / 180);
        var result2_d = Math.tan(radians2);
        var result2 = result2_d;

        //斜率为15度的两条直线
        var k33 = (k3 + result2) / (1 - k3 * result2);
        var b33 = controlPoints[5].y - k33 * controlPoints[5].x;

        var k34 = (k3 - result2) / (1 + k3 * result2);
        var b34 = controlPoints[5].y - k34 * controlPoints[5].x;
        drawPoints[0] = new ol.dmp.Point({x:controlPoints[5].x,y:controlPoints[5].y});


        //30度夹角直线的交点
        drawPoints[1] = new ol.dmp.Point({ x:(b31 - b1) / (k1 - k31), y: (b1 * k31 - b31 * k1) / (k31 - k1) });

        drawPoints[2] = new ol.dmp.Point({ x:(b32 - b1) / (k1 - k32), y:(b1 * k32 - b32 * k1) / (k32 - k1)  });;


        //15度夹角直线的交点
        drawPoints[3] = new ol.dmp.Point({ x:(b33 - b2) / (k2 - k33), y: (b2 * k33 - b33 * k2) / (k33 - k2) });;

        drawPoints[4] = new ol.dmp.Point({ x:(b34 - b2) / (k2 - k34), y:(b2 * k34 - b34 * k2) / (k34 - k2)});;


        leftPoints[3] = drawPoints[4];
        leftPoints[1] = curvePoints[1];
        leftPoints[2] = leftPoints[3];
        rightPoints[0] = drawPoints[3];
        rightPoints[1] = curvePoints[1];
        rightPoints[2] = points[1];
        rightPoints[3] = points[1];


        var linePoints = [];
        linePoints=linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(leftPoints));
           
        linePoints.push(drawPoints[2]);
        linePoints.push(drawPoints[0]);
        linePoints.push(drawPoints[1]);

        linePoints= linePoints.concat(ol.dmp.algorithmsUtility.Bezier.GetBezier3(rightPoints));
        
        if (isReasil != 1)
        {
            return linePoints.reverse();
        }
        else
        {
            return linePoints;
        }

    }


    

};




// bezier  贝塞尔曲线



ol.dmp.algorithmsUtility.Bezier = function ()
{ }

ol.dmp.algorithmsUtility.Bezier.BezierPoint2 = function (curvePoint, t)
{
    var newPoint = new ol.dmp.Point();
    newPoint.x = (1 - t) * (1 - t) * curvePoint[0].x + 2 * t * (1 - t) * curvePoint[1].x + t * t * curvePoint[2].x;
    newPoint.y = (1 - t) * (1 - t) * curvePoint[0].y + 2 * t * (1 - t) * curvePoint[1].y + t * t * curvePoint[2].y;
    return newPoint;
}

 ol.dmp.algorithmsUtility.Bezier.ClockWise= function (keyPoints)
{
    var i, j, k;
    var count = 0;
    var z;
    for (i = 0; i < 3; i++)
    {
        j = (i + 1) % 3;
        k = (i + 2) % 3;
        z = (keyPoints[j].y - keyPoints[i].y) * (keyPoints[k].x - keyPoints[j].x);
        z -= (keyPoints[j].x - keyPoints[i].x) * (keyPoints[k].y - keyPoints[j].y);
        if (z < 0)
            count--;
        else if (z > 0)
            count++;
    }
    if (count > 0)
        return 2;
    else if (count < 0)
        return 1;
    else
        return 0;
}

// 计算对称点
 ol.dmp.algorithmsUtility.Bezier.GetSymmetricalPoint=function(xielv, P, InputPoint)
{
    var A = xielv;
    var B = -1;
    var C = P.y - xielv * P.x;

    var Y = ((A * A - B * B) * InputPoint.y - 2 * A * B * InputPoint.x - 2 * B * C) / (A * A + B * B);
    var X = (Y - InputPoint.y) * A / B + InputPoint.x;
    return new ol.dmp.Point({ x: X, y: Y });
}

 ol.dmp.algorithmsUtility.Bezier.GetBezier3=function(bezierPoints)
{
    var rpoints = [];
    var rate = 50;
    var t, t1, t2, xt, yt;
    for (t = 0; t <= 1; t += 1.0 / rate)
    {
        yt = 1 - t;
        t1 = yt * yt;
        t2 = 3 * yt * t;
        xt = bezierPoints[0].x * t1 * yt + bezierPoints[1].x * t2 * yt + bezierPoints[2].x * t2 * t + bezierPoints[3].x * t * t * t;
        yt = bezierPoints[0].y * t1 * yt + bezierPoints[1].y * t2 * yt + bezierPoints[2].y * t2 * t + bezierPoints[3].y * t * t * t;
        rpoints.push(new ol.dmp.Point({ x: xt, y: yt }));
    }
    return rpoints;
}

/// 生成三次贝塞尔曲线点
 ol.dmp.algorithmsUtility.Bezier.GetBezier31=function(bezierPoints)
{
    var rpoints = [];
    var rate = 50;
    var t, t1, t2, xt, yt;
    for (t = 1; t >= 0; t -= 1.0 / rate)
    {
        yt = 1 - t;
        t1 = yt * yt;
        t2 = 3 * yt * t;
        xt = bezierPoints[0].x * t1 * yt + bezierPoints[1].x * t2 * yt + bezierPoints[2].x * t2 * t + bezierPoints[3].x * t * t * t;
        yt = bezierPoints[0].y * t1 * yt + bezierPoints[1].y * t2 * yt + bezierPoints[2].y * t2 * t + bezierPoints[3].y * t * t * t;
        rpoints.push(new ol.dmp.Point({ x: xt, y: yt }));
    }
    return rpoints;
}


